package com.jike.noobmoney.adapter;


import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.entity.MyPushEntity;


/**
 * Created by kekex on 2018/9/8.
 * 我的发布
 */

public class MyPushListAdapter extends BaseRecyclerAdapter<MyPushEntity.TaskBean> implements View.OnClickListener {


    private Context context;

    public MyPushListAdapter(Context context) {
        super(R.layout.item_my_push_list_new);
        this.context = context;

    }

    private ChildClickLis childClickLis;

    public void setChildClickLis(ChildClickLis childClickLis) {
        this.childClickLis = childClickLis;
    }

    public interface ChildClickLis {
        //审核
        void shenhe(String t_id);

        //退款
        void tuikaun(String t_id);

        //加票
        void jiapiao(String t_id);
        //update
        void update(String t_id);
        //置顶
        void top(MyPushEntity.TaskBean item);
        //上架
        void up(String t_id);
        //下架
        void down(String t_id);
    }

    @Override
    protected void onBindViewHolder(SmartViewHolder holder, MyPushEntity.TaskBean item, int position) {
        //任务id
        holder.text(R.id.tv_task_number, "悬赏ID: "+item.getT_id());

        //任务名称
        holder.text(R.id.tv_taskname, (TextUtils.isEmpty(item.getTaskname()) ? "小白任务" : item.getTaskname()));

        //已完成
        holder.text(R.id.tv_donnum,"进行中："+item.donumber);

        //发布时间
        holder.text(R.id.tv_tasktime,  item.getCreatetime());
        //已完成
        holder.text(R.id.tv_finishnum,"已完成："+item.getFinishnumber());

        //下架时间
        holder.text(R.id.tv_downtime,item.downtime);
        //审核周期

        holder.text(R.id.tv_autopasstime,item.autopasstime);

        //不合格
        holder.text(R.id.tv_badnumber,"审核失败："+item.badnumber);

        //总量
        holder.text(R.id.tv_number, "总量:" + item.getNumber());
        //为完成量
        holder.text(R.id.tv_lastnumber, "剩余:" + item.getLastnumber());

        RelativeLayout rl_sh=(RelativeLayout)holder.findViewById(R.id.rl_hz);
        TextView tvShenHe = (TextView) holder.findViewById(R.id.tv_shenhe);
        TextView tv_update = (TextView) holder.findViewById(R.id.tv_update);
        TextView tv_top = (TextView) holder.findViewById(R.id.tv_top);
        TextView tv_up = (TextView) holder.findViewById(R.id.tv_up);
        TextView tv_down = (TextView) holder.findViewById(R.id.tv_down);
        TextView tvTuiKuan = (TextView) holder.findViewById(R.id.tv_tuikua);
        TextView tvJiaPiao = (TextView) holder.findViewById(R.id.tv_jiapiao);
        TextView tv_dot = (TextView) holder.findViewById(R.id.tv_dot);
        TextView tv_reason=(TextView)holder.findViewById(R.id.tv_reason);

        //状态
        holder.text(R.id.tv_status2, "状态:" + item.getStatus2name());
        holder.text(R.id.tv_reason, "失败原因:" + item.getStatus2name());
        if(item.getStatussee()==1)
        {
            //只显示编辑
            tv_update.setVisibility(View.GONE);
            rl_sh.setVisibility(View.GONE);
            tv_top.setVisibility(View.GONE);
            tv_up.setVisibility(View.GONE);
            tv_down.setVisibility(View.GONE);
            tvTuiKuan.setVisibility(View.GONE);
            tvJiaPiao.setVisibility(View.GONE);
            tv_reason.setVisibility(View.GONE);

        }else if(item.getStatussee()==2)
        {
            tv_update.setVisibility(View.GONE);
            rl_sh.setVisibility(View.VISIBLE);
            tv_top.setVisibility(View.VISIBLE);
            tv_up.setVisibility(View.GONE);
            tv_down.setVisibility(View.VISIBLE);
            tvTuiKuan.setVisibility(View.VISIBLE);
            tvJiaPiao.setVisibility(View.VISIBLE);
            tv_reason.setVisibility(View.GONE);

            if(item.waitnumber>0){
                tv_dot.setVisibility(View.VISIBLE);
            }else
            {
                tv_dot.setVisibility(View.GONE);
            }

        }else if(item.getStatussee()==3)
        {

            tv_update.setVisibility(View.VISIBLE);
            rl_sh.setVisibility(View.GONE);
            tv_top.setVisibility(View.GONE);
            tv_up.setVisibility(View.GONE);
            tv_down.setVisibility(View.GONE);
            tvTuiKuan.setVisibility(View.GONE);
            tvJiaPiao.setVisibility(View.GONE);
            tv_reason.setVisibility(View.VISIBLE);
        }else if(item.getStatussee()==4)
        {
            tv_update.setVisibility(View.GONE);
            rl_sh.setVisibility(View.VISIBLE);
            tv_top.setVisibility(View.GONE);
            tv_up.setVisibility(View.VISIBLE);
            tv_down.setVisibility(View.GONE);
            tvTuiKuan.setVisibility(View.VISIBLE);
            tvJiaPiao.setVisibility(View.VISIBLE);
            tv_reason.setVisibility(View.GONE);
            if(item.waitnumber>0){
                tv_dot.setVisibility(View.VISIBLE);
            }else
            {
                tv_dot.setVisibility(View.GONE);
            }
        }else if(item.getStatussee()==5)
        {
            tv_update.setVisibility(View.GONE);
            rl_sh.setVisibility(View.VISIBLE);
            tv_top.setVisibility(View.GONE);
            tv_up.setVisibility(View.GONE);
            tv_down.setVisibility(View.GONE);
            tvTuiKuan.setVisibility(View.GONE);
            tvJiaPiao.setVisibility(View.GONE);
            tv_reason.setVisibility(View.GONE);
            if(item.waitnumber>0){
                tv_dot.setVisibility(View.VISIBLE);
            }else
            {
                tv_dot.setVisibility(View.GONE);
            }

        }else if(item.getStatussee()==6)
        {
            tv_update.setVisibility(View.GONE);
            rl_sh.setVisibility(View.GONE);
            tv_top.setVisibility(View.GONE);
            tv_up.setVisibility(View.GONE);
            tv_down.setVisibility(View.GONE);
            tvTuiKuan.setVisibility(View.GONE);
            tvJiaPiao.setVisibility(View.GONE);
            tv_reason.setVisibility(View.GONE);
        }
        //已开启和已关闭的可以申请
        rl_sh.setOnClickListener(view -> {
            int t_id = item.getT_id();
            if (childClickLis != null) {
                childClickLis.shenhe(String.valueOf(t_id));
            }
        });

        tvTuiKuan.setOnClickListener(view -> {
            int t_id = item.getT_id();
            if (childClickLis != null) {
                childClickLis.tuikaun(String.valueOf(t_id));
            }
        });


        tvJiaPiao.setOnClickListener(view -> {
            int t_id = item.getT_id();
            if (childClickLis != null) {
                childClickLis.jiapiao(String.valueOf(t_id));
            }
        });
        tv_update.setOnClickListener(view -> {
            int t_id = item.getT_id();
            if (childClickLis != null) {
                childClickLis.update(String.valueOf(t_id));
            }
        });
        tv_top.setOnClickListener(view -> {
            if (childClickLis != null) {
                childClickLis.top(item);
            }
        });
        tv_up.setOnClickListener(view -> {
            int t_id = item.getT_id();
            if (childClickLis != null) {
                childClickLis.up(String.valueOf(t_id));
            }
        });
        tv_down.setOnClickListener(view -> {
            int t_id = item.getT_id();
            if (childClickLis != null) {
                childClickLis.down(String.valueOf(t_id));
            }
        });


        holder.findViewById(R.id.tv_qiyong).setOnClickListener(this);
        holder.findViewById(R.id.tv_tingyong).setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tv_shenhe) {
            //审核
        } else if (id == R.id.tv_qiyong) {
            //启用
        } else if (id == R.id.tv_tingyong) {
            //停用
        } else if (id == R.id.tv_tuikua) {
            //退款
        }

    }
}
